package cn.cool.test;

import cn.cool.CdService;
import cn.cool.basic.CdDropDownOperate;
import cn.cool.basic.CdResource;
import cn.cool.common.CdResult;
import cn.cool.logic.CdLogicImpl;

import java.util.Iterator;
import java.util.Properties;

public class Main {

/*    private static void setConstData(CdDropDownOperate constOperate) {
        System.out.println(constOperate.setConstData(null, "df_key_one", "df_value_one"));
        System.out.println(constOperate.setConstData(null, "df_key_two", "df_value_two"));
        System.out.println(constOperate.setConstData("domain", "dm_key_one", "dm_value_one"));
        System.out.println(constOperate.setConstData("domain", "dm_key_two", "dm_value_two"));
        System.out.println(constOperate.setConstData("domain", "dm_key_two", "dm_value_two_upd"));
        System.out.println(constOperate.setConstData("domain", "dm_key_three", "锄禾日当午，,.。!#$%^&*()_+~！@#￥%……&*（）——+"));
    }

    private static void getConstData(CdDropDownOperate constOperate) {
        System.out.println(constOperate.getConstData(null, "df_key_two"));
        System.out.println(constOperate.getConstData(null, "df_key_two_n1"));
        System.out.println(constOperate.getConstData("domain", "dm_key_two"));
        System.out.println(constOperate.getConstData("domain", "dm_key_two_n1"));
    }*/

    // 读取配置文件
    private static void getPropertiesFile() {
        CdResource cdResource = new CdResource();
        // 顺序读取
        Properties prop = cdResource.readResource(null);

        Iterator<Object> iterator = prop.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next().toString();
            String value = prop.getProperty(key);
            System.out.println("顺序读取 " + key + ":" + value);
        }
    }

    private static void initProperties() {
        CdDropDownOperate.initSettingData();

        System.out.println("数据 : " + CdDropDownOperate.getAllConstData());
    }

    private static void testCdLogic() {
        CdLogicImpl cdLogic = new CdLogicImpl();

        // 获取所有数据
        //CdResult allData = cdLogic.getAllData();
        //System.out.println(allData.getCode());

        // 获取命名所有数据
        //CdResult namespaceData = cdLogic.getAllNameSpaceData();

        // 获取类型所有数据
        //CdResult typeData = cdLogic.getAllTypeData("domain");
        //CdResult typeData = cdLogic.getAllTypeData("order");
        //System.out.println(typeData.getCode());

        // 获取全部命名空间类型下的值数据
        //CdResult valueData = cdLogic.getAllTypeKeyData("order", "goodsStatus");
        //System.out.println(valueData.getCode());

        // 获取命名空间类型下具体key键的数据值
        //CdResult keyData = cdLogic.getKeyData("domain", "goodsStatus", "refund");
        //System.out.println(keyData.getCode());

        // 获取命名空间类型的下拉项数据
        //List<CdDropdownItem> itemList = cdLogic.getDropDownListData("domain", "saleStatus");
        //System.out.println(itemList.size());

        // 获取命名空间类型包含首项的下拉项数据
        //List<CdDropdownItem> itemList = cdLogic.getDropDownListTopEmptyData("domain", "saleStatus");
        //System.out.println(itemList.size());

        // 获取命名空间数据个数
        //System.out.println(cdLogic.getNameSpaceCount());

        // 获取命名空间下类型个数
        //System.out.println(cdLogic.getTypeCount("order"));

        // 获取命名空间下类型的key个数
        System.out.println(cdLogic.getTypeKeyCount("order", "payStatus"));
        System.out.println(CdService.getTypeKeyCount("order", "payStatus"));
    }

    public static void main(String[] args) {
        //CdDropDownOperate constOperate = new CdDropDownOperate();
        //setConstData(constOperate);
        //getConstData(constOperate);
        //System.out.println(constOperate.getAllConstData().getData());

        // --------------------------- 分隔符 ---------------------------
        // CcUtil.printCcConstantInfo(); // 打印常量信息

        // --------------------------- 分隔符 ---------------------------

        //getPropertiesFile(); // 读取配置文件
        initProperties();
        testCdLogic();
    }

}
